package com.gsbelarus.gedemin.salary.util;

import com.gsbelarus.gedemin.salary.entity.model.DayEventModel;
import com.gsbelarus.gedemin.salary.entity.model.EmployeeModel;
import com.gsbelarus.gedemin.salary.entity.model.ExRatesMonthlyModel;
import com.gsbelarus.gedemin.salary.entity.model.GdMsgEmployeeModel;
import com.gsbelarus.gedemin.salary.entity.model.GdMsgHolidayModel;
import com.gsbelarus.gedemin.salary.entity.model.GdMsgIncomeModel;
import com.gsbelarus.gedemin.salary.entity.model.GdMsgInfoModel;
import com.gsbelarus.gedemin.salary.entity.model.GdMsgModel;
import com.gsbelarus.gedemin.salary.entity.model.GdMsgVacationModel;
import com.gsbelarus.gedemin.salary.entity.model.GdMsgWorkScheduleModel;
import com.gsbelarus.gedemin.salary.entity.model.PayslipBenefitModel;
import com.gsbelarus.gedemin.salary.entity.model.PayslipDeductionModel;
import com.gsbelarus.gedemin.salary.entity.model.PayslipItemModel;
import com.gsbelarus.gedemin.salary.entity.model.PayslipModel;
import com.gsbelarus.gedemin.salary.entity.model.SyncGdMsgStateModel;
import com.gsbelarus.gedemin.salary.entity.model.TimesheetModel;
import com.gsbelarus.gedemin.salary.entity.model.WorkScheduleModel;

import java.util.Date;
import java.util.UUID;

/// TODO Временно!

public class ModelFactory {

    public static SyncGdMsgStateModel newInstanceSyncGdMsgStatusModel(SyncGdMsgStateModel model, SyncGdMsgStateModel.UpdatedStatus updatedStatus, Integer gdMsgKey) {
        model.setUid(UUID.randomUUID().toString());

        model.setStatus(updatedStatus);
        model.setGdMsgKey(gdMsgKey);
        return model;
    }

    public static EmployeeModel newInstanceEmployeeModel(EmployeeModel model, String firstname, String surname, String middlename, String personalNumber, String listNumber) {
        model.setUid(UUID.randomUUID().toString());

        model.setFirstname(firstname);
        model.setSurname(surname);
        model.setMiddlename(middlename);
        model.setPersonalNumber(personalNumber);
        model.setListNumber(listNumber);
        return model;
    }

    public static ExRatesMonthlyModel newInstanceExRatesMonthlyModel(ExRatesMonthlyModel model, Date onDate, double usdRate, double eurRate) {
        model.setUid(UUID.randomUUID().toString());

        model.setOnDate(onDate);
        model.setUsdRate(usdRate);
        model.setEurRate(eurRate);
        return model;
    }

    public static PayslipItemModel newInstancePayslipItemModel(PayslipItemModel model, PayslipItemModel.Category category, Date date, String name, int code, double debit, double credit) {
        model.setUid(UUID.randomUUID().toString());

        model.setCategory(category);
        model.setDate(date);
        model.setName(name);
        model.setCode(code);
        model.setDebit(debit);
        model.setCredit(credit);
        return model;
    }

    public static PayslipBenefitModel newInstancePayslipBenefitModel(PayslipBenefitModel model, Date date, String name, double sum) {
        model.setUid(UUID.randomUUID().toString());

        model.setDate(date);
        model.setName(name);
        model.setSum(sum);
        return model;
    }

    public static PayslipDeductionModel newInstancePayslipDeductionModel(PayslipDeductionModel model, Date date, String name, String deductionKind, double sum) {
        model.setUid(UUID.randomUUID().toString());

        model.setDate(date);
        model.setName(name);
        model.setDeductionKind(deductionKind);
        model.setSum(sum);
        return model;
    }

    /// без списков
    public static PayslipModel newInstancePayslipModel(PayslipModel model, Date payDate, EmployeeModel employee, String department, String position, double salary, double hourRate) {
        model.setUid(UUID.randomUUID().toString());
        model.setPayDate(payDate);
        model.setEmployee(employee);
        model.setDepartment(department);
        model.setPosition(position);
        model.setSalary(salary);
        model.setHourRate(hourRate);
        return model;
    }

    public static DayEventModel newInstanceDayEventModel(DayEventModel model, DayEventModel.EventType eventType, String description, boolean isAllDay) {
        model.setUid(UUID.randomUUID().toString());

        model.setEventType(eventType);
        model.setDescription(description);
        model.setAllDay(isAllDay);
        return model;
    }

    public static DayEventModel newInstanceDayEventModel(DayEventModel model, DayEventModel.EventType eventType, Date timeBegin, Date timeEnd, String description, boolean isAllDay) {
        model.setUid(UUID.randomUUID().toString());

        model.setEventType(eventType);
        model.setTimeBegin(timeBegin);
        model.setTimeEnd(timeEnd);
        model.setDescription(description);
        model.setAllDay(isAllDay);
        return model;
    }

    /// без списков
    public static WorkScheduleModel newInstanseWorkScheduleModel(WorkScheduleModel model, WorkScheduleModel.DayType dayType, EmployeeModel employee, Date date) {
        model.setUid(UUID.randomUUID().toString());

        model.setDayType(dayType);
        model.setEmployee(employee);
        model.setDate(date);
        return model;
    }

    /// без списков
    public static TimesheetModel newInstanceTimesheetModel(TimesheetModel model, EmployeeModel employee, Date date) {
        model.setUid(UUID.randomUUID().toString());

        model.setEmployee(employee);
        model.setDate(date);
        return model;
    }


    /// без subModel
    // create client message
    public static GdMsgModel newInstanceGdMsgModel(int uid, GdMsgModel model, GdMsgModel.Subject subject, String comment, Date timestamp) {
        model.setSubject(subject);
        model.setMsg("");
        model.setComment(comment);
        model.setTimestamp(timestamp);

        model.setUid(uid);
        model.setRequestStatus(GdMsgModel.RequestStatus.UNKNOWN);
        model.setIsUnread(false);
        model.setSender(GdMsgModel.Sender.CLIENT);
        return model;
    }

    /// без subModel
    // create server message
    public static GdMsgModel newInstanceGdMsgModel(int uid, GdMsgModel model, GdMsgModel.Subject subject, String msg, String comment, Date timestamp,
                                                   GdMsgModel.RequestStatus requestStatus) {
        model.setSubject(subject);
        model.setMsg(msg);
        model.setComment(comment);
        model.setTimestamp(timestamp);
        model.setUid(uid);
        model.setRequestStatus(requestStatus);

        model.setIsUnread(true);
        model.setSender(GdMsgModel.Sender.SERVER);
        return model;
    }


    // create client message
    public static GdMsgModel newInstanceGdMsgEmployeeModel(int subUid, GdMsgEmployeeModel subModel, int uid, GdMsgModel model, String comment, Date timestamp,
                                                           EmployeeModel employeeModel) {
        subModel.setUid(subUid);
        subModel.setEmployeeModel(employeeModel);

        newInstanceGdMsgModel(uid, model, GdMsgModel.Subject.CHANGE_USER_PROFILE, comment, timestamp);
        model.setGdMsgEmployeeModel(subModel);
        model.setGdMsgString(ExtractStringHelper.gdMsgToString(model));
        return model;
    }

    // create server message
    public static GdMsgModel newInstanceGdMsgEmployeeModel(int subUid, GdMsgEmployeeModel subModel, int uid, GdMsgModel model, String msg, String comment, Date timestamp,
                                                           GdMsgModel.RequestStatus requestStatus, GdMsgModel requestGdMsg) {
        subModel.setUid(subUid);
        subModel.setRequestGdMsgModel(requestGdMsg);

        newInstanceGdMsgModel(uid, model, GdMsgModel.Subject.CHANGE_USER_PROFILE, msg, comment, timestamp, requestStatus);
        model.setGdMsgEmployeeModel(subModel);
        model.setGdMsgString(ExtractStringHelper.gdMsgToString(model));
        return model;
    }


    // create client message
    public static GdMsgModel newInstanceGdMsgHolidayModel(int subUid, GdMsgHolidayModel subModel, int uid, GdMsgModel model, String comment, Date timestamp,
                                                          Date dateBegin, Date dateEnd, GdMsgHolidayModel.Type type) {
        subModel.setUid(subUid);
        subModel.setDateBegin(dateBegin);
        subModel.setDateEnd(dateEnd);
        subModel.setType(type);

        newInstanceGdMsgModel(uid, model, GdMsgModel.Subject.HOLIDAY, comment, timestamp);
        model.setGdMsgHolidayModel(subModel);
        model.setGdMsgString(ExtractStringHelper.gdMsgToString(model));
        return model;
    }

    // create server message
    public static GdMsgModel newInstanceGdMsgHolidayModel(int subUid, GdMsgHolidayModel subModel, int uid, GdMsgModel model, String msg, String comment, Date timestamp,
                                                          GdMsgModel.RequestStatus requestStatus, GdMsgModel requestGdMsg) {
        subModel.setUid(subUid);
        subModel.setRequestGdMsgModel(requestGdMsg);

        newInstanceGdMsgModel(uid, model, GdMsgModel.Subject.HOLIDAY, msg, comment, timestamp, requestStatus);
        model.setGdMsgHolidayModel(subModel);
        model.setGdMsgString(ExtractStringHelper.gdMsgToString(model));
        return model;
    }


    // create client message
    public static GdMsgModel newInstanceGdMsgIncomeModel(int subUid, GdMsgIncomeModel subModel, int uid, GdMsgModel model, String comment, Date timestamp,
                                                         Date dateBegin, Date dateEnd) {
        subModel.setUid(subUid);
        subModel.setDateBegin(dateBegin);
        subModel.setDateEnd(dateEnd);

        newInstanceGdMsgModel(uid, model, GdMsgModel.Subject.INCOME, comment, timestamp);
        model.setGdMsgIncomeModel(subModel);
        model.setGdMsgString(ExtractStringHelper.gdMsgToString(model));
        return model;
    }

    // create server message
    public static GdMsgModel newInstanceGdMsgIncomeModel(int subUid, GdMsgIncomeModel subModel, int uid, GdMsgModel model, String msg, String comment, Date timestamp,
                                                         GdMsgModel.RequestStatus requestStatus, GdMsgModel requestGdMsg) {
        subModel.setRequestGdMsgModel(requestGdMsg);
        subModel.setUid(subUid);

        newInstanceGdMsgModel(uid, model, GdMsgModel.Subject.INCOME, msg, comment, timestamp, requestStatus);
        model.setGdMsgIncomeModel(subModel);
        model.setGdMsgString(ExtractStringHelper.gdMsgToString(model));
        return model;
    }


    // create client message
    public static GdMsgModel newInstanceGdMsgVacationModel(int subUid, GdMsgVacationModel subModel, int uid, GdMsgModel model, String comment, Date timestamp,
                                                           Date dateBegin, Date dateEnd, GdMsgVacationModel.Type type) {
        subModel.setUid(subUid);
        subModel.setDateBegin(dateBegin);
        subModel.setDateEnd(dateEnd);
        subModel.setType(type);

        newInstanceGdMsgModel(uid, model, GdMsgModel.Subject.VACATION, comment, timestamp);
        model.setGdMsgVacationModel(subModel);
        model.setGdMsgString(ExtractStringHelper.gdMsgToString(model));
        return model;
    }

    // create server message
    public static GdMsgModel newInstanceGdMsgVacationModel(int subUid, GdMsgVacationModel subModel, int uid, GdMsgModel model, String msg, String comment, Date timestamp,
                                                           GdMsgModel.RequestStatus requestStatus, GdMsgModel requestGdMsg) {
        subModel.setUid(subUid);
        subModel.setRequestGdMsgModel(requestGdMsg);

        newInstanceGdMsgModel(uid, model, GdMsgModel.Subject.VACATION, msg, comment, timestamp, requestStatus);
        model.setGdMsgVacationModel(subModel);
        model.setGdMsgString(ExtractStringHelper.gdMsgToString(model));
        return model;
    }


    // create server message
    public static GdMsgModel newInstanceWorkScheduleGdMsgModel(int subUid, GdMsgWorkScheduleModel subModel, int uid, GdMsgModel model, String msg, String comment, Date timestamp,
                                                               GdMsgModel.RequestStatus requestStatus) {
        subModel.setUid(subUid);

        newInstanceGdMsgModel(uid, model, GdMsgModel.Subject.CHANGE_WORK_SCHEDULE, msg, comment, timestamp,requestStatus);
        model.setGdMsgWorkScheduleModel(subModel);
        model.setGdMsgString(ExtractStringHelper.gdMsgToString(model));
        return model;
    }

    // create server message
    public static GdMsgModel newInstanceGdMsgInfoModel(int subUid, GdMsgInfoModel subModel, int uid, GdMsgModel model, String msg, String comment, Date timestamp,
                                                       GdMsgModel.RequestStatus requestStatus) {
        subModel.setUid(subUid);

        newInstanceGdMsgModel(uid, model, GdMsgModel.Subject.INFO, msg, comment, timestamp,requestStatus);
        model.setGdMsgInfoModel(subModel);
        model.setGdMsgString(ExtractStringHelper.gdMsgToString(model));
        return model;
    }
}
